﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RBAC.Web.Service;
using RBAC.Web.Models;
namespace RBAC.Web.Mapper
{
    public class FunctionMapper
    {
        public static FunctionModel DtoToModel(FunctionDto inputDto)
        {
            FunctionModel result = new FunctionModel();

            result.Id = inputDto.Id;
            result.FuncName = inputDto.FuncName;
            result.Description = inputDto.Description;

            result.CreateDate = inputDto.CreateDate;
            result.CreateById = inputDto.CreateById;
            result.FunctionStatus = inputDto.IsActive.GetValueOrDefault() ? 1 : 2;

            if (inputDto.Domain != null)
            {
                result.Domain = inputDto.Domain.Id;

                result.DomainId = inputDto.Domain.Id;
                result.DomainDomainName = inputDto.Domain.DomainName;

            }
            //result.FunctionStatus = inputDto.FunctionStatus;
            result.FunctionName = inputDto.FunctionName;

            if (inputDto.DomainLookup != null)
            {
                result.DomainLookup = inputDto.DomainLookup.Id;

                result.DomainLookupId = inputDto.DomainLookup.Id;
                result.DomainLookupDomainName = inputDto.DomainLookup.DomainName;

            }

            return result;
        }


        public static FunctionDto ModelToDto(FunctionModel inputModel)
        {


            FunctionDto result = new FunctionDto();

            result.Id = inputModel.Id;
            result.FuncName = inputModel.FuncName;
            result.Description = inputModel.Description;
            if (inputModel.Domain != 0)
            {
                result.Domain = new DomainDto() { Id = inputModel.Domain };
            }
            else
            {
                //result.Domain = new DomainDto();
                result.Domain = null;
            }

            //result.FunctionStatus = inputModel.FunctionStatus;
            result.FunctionName = inputModel.FunctionName;
            if (inputModel.DomainLookup != 0)
            {
                result.DomainLookup = new DomainDto() { Id = inputModel.DomainLookup };
            }
            else
            {
                //result.DomainLookup = new DomainDto();
                result.DomainLookup = null;
            }


            result.CreateDate = inputModel.CreateDate;
            result.CreateById = inputModel.CreateById ;
            result.IsActive = inputModel.FunctionStatus == 1;


            return result;
        }

    }
}